﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.Web.coffinegurunaru.AppLogic.Page;
using Com.Framework;
using Com.Framework.Data;
using Com.Library.DB.Event;

namespace Com.Web.coffinegurunaru.whatsnew
{
	public partial class event_view : WebPage
	{
		public int EventSN { get; set; }
		public int PageNo { get; set; }
		public int CPageNo { get; set; }
		public byte CPageSize { get { return 10; } }

		public EventEntity EventInfo { get; set; }
		public EventMoveEntity EventMoveInfo { get; set; }
		public List<EventCommentEntity> EventCommentList { get; set; }

		protected void Page_Load(object sender, EventArgs e)
		{
			this.LeftMenuType = 1;
			EventSN = Request.QueryString["EventSN"].Parse(0);
			PageNo = Request.QueryString["PageNo"].Parse(1);
			CPageNo = Request.QueryString["CPageNo"].Parse(1);

			if (EventSN == 0)
			{
				Response.Redirect("/whatsnew/event.aspx");
				return;
			}

			if (this.IsPostBack)
			{
				if (this.WebCookies.IsLogin)
				{
					string Comment = Request.Form["CommentContent"].Parse(string.Empty);
					int EventCommentSN = Request.Form["EventCommentSN"].Parse(0);
					string EventType = Request.Form["EventType"].Parse(string.Empty);

					if (EventCommentSN == 0)
					{
						EventModel.CommentCreate(EventSN, this.WebCookies.UserNo, this.WebCookies.UserID, this.WebCookies.UserName, Request.UserHostAddress, Comment);
						Response.Redirect("/whatsnew/event_view.aspx?EventSN=" + EventSN.ToString() + "&PageNo=" + PageNo.ToString() + "&CPageNo=" + CPageNo.ToString());
					}
					else
					{
						if (EventType == "remove")
						{
							EventModel.CommentRemove(EventCommentSN);
							Response.Redirect("/whatsnew/event_view.aspx?EventSN=" + EventSN.ToString() + "&PageNo=" + PageNo.ToString() + "&CPageNo=" + CPageNo.ToString());
						}
						else if (EventType == "modify")
						{
							Comment = Request.Form["txtComment_" + EventCommentSN.ToString()].Parse(string.Empty);
							EventModel.CommentModify(EventCommentSN, Comment, Request.UserHostAddress);
							Response.Redirect("/whatsnew/event_view.aspx?EventSN=" + EventSN.ToString() + "&PageNo=" + PageNo.ToString() + "&CPageNo=" + CPageNo.ToString());
						}
					}
					return;
				}
				else
				{
					Response.Write("<script>alert('로그인하셔야합니다.')</script>");
				}
			}

			EventInfo = EventModel.GetInfo(EventSN);
			EventMoveInfo = EventModel.GetMoveInfo(EventSN);
			ListData<EventCommentEntity, OutputEntity> Result = EventModel.CommentGetList(EventSN, CPageNo, CPageSize);
			EventCommentList = Result.Record;
			UC_Paging.TotalCount = Result.Output.CntTotal;
			UC_Paging.PageName = "CPageNo";
			UC_Paging.PageNo = CPageNo;
			UC_Paging.PageSize = CPageSize;
			UC_Paging.Query = "PageNo=" + PageNo.ToString() + "&EventSN=" + EventSN.ToString();
		}

		public string GetContentAlign(byte CodeContent)
		{
			if (CodeContent == 1) return "style='text-align:left'";
			if (CodeContent == 2) return "style='text-align:center'";
			if (CodeContent == 3) return "style='text-align:right'";
			return string.Empty;
		}
	}
}
